package Community;

import com.opensymphony.xwork2.ActionSupport;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

import java.io.Reader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;



public class viewAction extends ActionSupport{
	
	public static Reader reader;
	public static SqlMapClient sqlMapper;
	
	private boardVO paramClass = new boardVO();
	private boardVO resultClass = new boardVO();
	private List<cboardVO> Ccommentlist = new ArrayList<cboardVO>();
	
	private cboardVO cClass = new cboardVO();
	private cboardVO cResult = new cboardVO();
	
	
	private int currentPage;
	
	private int c_content_num;
	private int comment_num;
	
	private String id;
	

	
	private InputStream inputStream;
	private String contentDisposition;
	private long contentLength;
	
	public viewAction() throws IOException
	{
		reader = Resources.getResourceAsReader("sqlMapConfig.xml");
		sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
		reader.close();
	}

	public String execute() throws Exception {
		paramClass.setC_content_num(getC_content_num());
		sqlMapper.update("communityboard.updateReadcount",paramClass);
		
		resultClass = (boardVO) sqlMapper.queryForObject("communityboard.selectOne", getC_content_num());
		
		Ccommentlist = sqlMapper.queryForList("communityboard.commentSelectAll", getC_content_num());
		
		return SUCCESS;
	}
	
	
	public String checkForm() throws Exception
	{
		return SUCCESS;
	}
	
	public String CcheckAction()	throws Exception
	{
		paramClass.setC_content_num(getC_content_num());
		paramClass.setId(getId());
		
		resultClass = (boardVO) sqlMapper.queryForObject("communityboard.selectId", paramClass);
		
		if(resultClass == null)
			return ERROR;
		
		return SUCCESS;
	}
	
	public String CcheckAction2()	throws Exception
	{
		cClass.setComment_num(getComment_num());
		cClass.setId(getId());
		
		cResult = (cboardVO) sqlMapper.queryForObject("communityboard.selectId2", cClass);
		
		if(cResult == null)
			return ERROR;
		
		return SUCCESS;
	}




	public List<cboardVO> getCcommentlist() {
		return Ccommentlist;
	}

	public void setCcommentlist(List<cboardVO> ccommentlist) {
		Ccommentlist = ccommentlist;
	}

	public boardVO getParamClass() {
		return paramClass;
	}

	public void setParamClass(boardVO paramClass) {
		this.paramClass = paramClass;
	}

	public boardVO getResultClass() {
		return resultClass;
	}

	public void setResultClass(boardVO resultClass) {
		this.resultClass = resultClass;
	}

	public cboardVO getcClass() {
		return cClass;
	}

	public void setcClass(cboardVO cClass) {
		this.cClass = cClass;
	}

	public cboardVO getcResult() {
		return cResult;
	}

	public void setcResult(cboardVO cResult) {
		this.cResult = cResult;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getC_content_num() {
		return c_content_num;
	}

	public void setC_content_num(int c_content_num) {
		this.c_content_num = c_content_num;
	}
	
	public int getComment_num() {
		return comment_num;
	}

	public void setComment_num(int comment_num) {
		this.comment_num = comment_num;
	}
	
	public String getId(){
		return id;
	}
	public void setId(String id){
		this.id = id;
	}

	public InputStream getInputStream() {
		return inputStream;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}

	public String getContentDisposition() {
		return contentDisposition;
	}

	public void setContentDisposition(String contentDisposition) {
		this.contentDisposition = contentDisposition;
	}

	public long getContentLength() {
		return contentLength;
	}

	public void setContentLength(long contentLength) {
		this.contentLength = contentLength;
	}
	
	

}
